package com.yanqingying.controller;
import com.yanqingying.aop.log;
import com.yanqingying.*;
import com.yanqingying.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    StudentServiceImpl studentService;

    @GetMapping()
    public Result gatPage(StudentQueryParam studentQueryParam) {
        PageBean pageBean = studentService.getPage(studentQueryParam);
        return Result.success(pageBean);
    }
    @log
    @DeleteMapping("/{ids}")
    public Result deletes(@PathVariable List<Integer> ids) {
        studentService.deletes(ids);
        return Result.success();

    }
    @log
    @PostMapping()
    public Result add(@RequestBody Student student) {
        studentService.add(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result gate(@PathVariable Integer id) {
        GetStudent getStudent = studentService.gate(id);
        return Result.success(getStudent);
    }
    @log
    @PutMapping()
    public Result upDate(@RequestBody GetStudent student){
        studentService.upDate(student);
        return Result.success();
    }
    @log
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id ,@PathVariable Integer score){
        studentService.violation(id, score);
        return Result.success();
    }


}
